Skip to content

Comments

Add session persistence and recovery for interrupted executions#18

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/enhance-session-persistence
Draft

Add session persistence and recovery for interrupted executions#18
Copilot wants to merge 6 commits intomainfrom
copilot/enhance-session-persistence

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Copilot SDK sessions persist across app restarts but Planeteer didn't track them. Interrupted executions left orphaned sessions consuming resources with no recovery path.

Changes

Session tracking

  • Added sessionId?: string to Task model and interrupted status type
  • Added onSessionStart callback to StreamCallbacks — session ID is captured when a session is created and stored on the task (replaces the earlier approach of changing sendPromptSync's return type)
  • Executor stores session IDs via onSessionStart callback, keeping sendPromptSync returning string

Incremental persistence

  • Added onPlanUpdate callback to executor, triggered after each task completes/fails
  • Execute screen saves plan incrementally during execution

Recovery on load

  • New session-recovery.ts service detects tasks with status: 'in_progress' and active sessions
  • Execute screen shows recovery prompt with options: continue with sessions, cleanup sessions, or abort
  • Async cleanup with proper error handling and loading states

SDK integration

  • Bumped @github/copilot-sdk to ^0.1.24 for listSessions() support
  • Added listSessions(), deleteSession(), resumeSession() wrapper functions

Session context display (merged from main)

  • Execute screen shows working directory and repository context per task using session.start events
  • onSessionEvent callback in executor propagates SDK session events to the UI

Example

// Session ID captured via callback when session is created
await sendPromptSync(prompt, messages, {
  onSessionStart: (sessionId) => {
    task.sessionId = sessionId;
  },
});

When loading a plan with interrupted tasks:

⚠ Orphaned Sessions Detected
Found 2 interrupted tasks with active sessions:
  • Implement auth logic (session: a1b2c3d4...)
  • Setup database (session: e5f6g7h8...)

Choose an option:
  1 — Mark as interrupted and continue (keeps sessions)
  2 — Mark as interrupted and cleanup sessions (recommended)
  3 — Cleanup sessions and go back

Testing

Added unit tests for markTasksAsInterrupted() covering multiple scenarios and immutability. All 23 tests pass.

Original prompt

This section details on the original issue you should resolve

<issue_title>[enhancement] Implement session persistence and recovery for interrupted executions</issue_title>
<issue_description>## Background

The Copilot SDK includes session persistence capabilities that allow SDK applications to list and reconnect to existing Copilot sessions. Recent SDK updates have enhanced this with:

  1. Session context tracking (v0.1.24) - SessionContext with working directory, git root, repository, and branch info
  2. Session filtering (v0.1.24) - listSessions() can filter by context fields in PR colindembovsky/planeteer#427 by Jeremy Moseley
  3. Improved session management - Better object disposal and lifecycle handling in PR colindembovsky/planeteer#481 by Steve Sanderson

These capabilities enable applications to reconnect to orphaned sessions after crashes or interruptions.

Related SDK commits:

Proposal

Implement session persistence and recovery in Planeteer to allow resuming interrupted executions:

  1. Session ID tracking: Store Copilot session IDs in the persisted plan when execution starts
  2. Graceful shutdown: On normal exit or Ctrl+C, properly dispose sessions and mark tasks as interrupted
  3. Recovery on restart: When loading a plan with incomplete tasks, detect orphaned sessions using listSessions() with repository context filtering
  4. Resume option: Offer users the choice to resume from orphaned sessions or start fresh execution
  5. Session cleanup: Provide a way to dispose orphaned sessions that are no longer needed

Implementation points:

  • Extend Task model with optional sessionId?: string field
  • Save plan JSON after each task completion (incremental persistence)
  • On load, check for tasks with status: 'running' and associated session IDs
  • Use listSessions({ filter: { repository, branch } }) to find orphaned sessions
  • Add "Resume" option in execute screen if orphaned sessions are detected

Benefit

Session persistence makes Planeteer more robust and production-ready:

  • Crash recovery: Users can resume work after unexpected crashes, network issues, or terminal closures
  • Long-running executions: For plans with many tasks, users can stop and resume execution across multiple sessions
  • Resource management: Prevents accumulation of orphaned Copilot sessions consuming resources
  • Professional UX: Matches user expectations from CI/CD and build tools that support resumable operations
  • Debugging: Users can inspect the state of failed executions and retry specific tasks

Acceptance Criteria

  • Add sessionId?: string field to Task interface in src/models/plan.ts
  • Update src/services/executor.ts to store session IDs when creating agent sessions
  • Implement incremental plan persistence - save plan JSON after each task completes or fails
  • On plan load, detect tasks with status: 'running' and check if their sessions still exist using listSessions()
  • Display orphaned sessions in execute screen with options: "Resume", "Start Fresh", "Clean Up"
  • Implement graceful shutdown handler (SIGINT/Ctrl+C) to dispose active sessions and mark tasks as interrupted
  • Add session cleanup utility to dispose orphaned sessions by repository context
  • Update SDK dependency to ^0.1.24 or later to ensure session context filtering is available
  • Add unit tests for session recovery logic
  • Document session persistence behavior in README

AI generated by Weekly Enhancement Suggestions

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 18, 2026 08:17
Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Add session persistence and recovery for interrupted executions Add session persistence and recovery for interrupted executions Feb 18, 2026
Copilot AI requested a review from colindembovsky February 18, 2026 08:28
@colindembovsky
Copy link
Owner

@copilot update this branch and resolve conflicts

… mode

Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 20, 2026

@copilot update this branch and resolve conflicts

Done. The branch has been updated (commit 4e274be) with all changes from main merged in:

  • Skills support (skill files, skill options in planner/executor, Skills view in refine screen)
  • Session events (session context tracking, cwd/repository/branch display in execute screen)
  • Simulator mode (new src/services/simulator.ts and CLI integration tests)
  • All existing session persistence features preserved (session ID tracking, incremental save, orphaned session recovery UI)

All 23 tests pass and the build is clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[enhancement] Implement session persistence and recovery for interrupted executions

2 participants